﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Configuration;
using System.Collections;

namespace  EasyDater.Helper
{
    public class ConfigHelper
    {
        public static string GetConString()
        { 
             return  ConfigurationManager.ConnectionStrings["MssqlConn"].ConnectionString.ToString();
        }

        //获取连接字符串中数据库的名称
        public string GetDatabaseName()
        {        
            string conn = GetConString();
            string[] strArray = conn.Split(new string[] { ";" }, StringSplitOptions.None);

            foreach (string str in strArray)
            {
                string[] strItemArray = str.Split(new string[] { "=" }, StringSplitOptions.None);
                if (strItemArray[0].Trim() == "Initial Catalog")
                {
                    return strItemArray[1].Trim();
                }
            }
            return "";
        
        }
        
    }
}
